package com.toe.forum.webapi.controller;


import com.toe.common.restful.JsonResult;
import com.toe.forum.service.ForumArticleService;
import com.toe.pojo.dto.forum.ArticleAddDTO;
import com.toe.pojo.dto.forum.ArticleUpdateDTO;
import com.toe.pojo.vo.forum.ArticleDetailVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
 * <p>
 * 文章表 前端控制器
 * </p>
 *
 * @author 陶涛
 * @since 2022-07-19
 */
@RestController
@RequestMapping("/forum-article")
@Api(tags = "文章模块")
public class ForumArticleController {

    @Autowired
    private ForumArticleService forumArticleService;

    @ApiOperation("添加文章")
    @PostMapping("/insert")
    public JsonResult<Void> insertArticle(@RequestBody ArticleAddDTO articleAddDTO){
        forumArticleService.insert(articleAddDTO);
        return JsonResult.ok();
    }

    @ApiOperation("删除文章")
    @PostMapping("/delete/{id}")
    public JsonResult<Void> deleteArticle(@PathVariable Long id){
        forumArticleService.deleteById(id);
        return JsonResult.ok();
    }

    @ApiOperation("修改文章")
    @PostMapping("/update")
    public JsonResult<Void> updateArticle(@RequestBody ArticleUpdateDTO articleUpdateDTO){
        forumArticleService.updateArticle(articleUpdateDTO);
        return JsonResult.ok();
    }

    @ApiOperation("查询所有文章")
    @GetMapping("/select/list")
    public JsonResult<List<ArticleDetailVO>> selectAllArticle(){
        List<ArticleDetailVO> articleDetailVOS = forumArticleService.selectAllArticle();
        return JsonResult.ok(articleDetailVOS);
    }

    @ApiOperation("分页查询所有的文章")
    @GetMapping("/select/list/page")
    public JsonResult<List<ArticleDetailVO>> selectAllArticlePage(Integer pageNum,Integer pageSize){
        List<ArticleDetailVO> articleDetailVOS = forumArticleService.selectAllArticlePage(pageNum, pageSize);
        return JsonResult.ok(articleDetailVOS);
    }

//    @ApiOperation("查询该分类的所有文章")
//    @GetMapping("/select/category/{categoryId}")
//    public JsonResult<List<ArticleDetailVO>> selectAllArticleByCategoryId(@PathVariable("categoryId") long categoryId){
//        List<ArticleDetailVO> articleDetailVOS = forumArticleService.selectAllArticleByCategoryId(categoryId);
//        return JsonResult.ok(articleDetailVOS);
//    }
//
//    @ApiOperation("分页查询该分类的所有文章")
//    @GetMapping("/select/category/{categoryId}/page")
//    public JsonResult<List<ArticleDetailVO>> selectAllArticleByCategoryId(@PathVariable("categoryId") long categoryId,Integer pageNum,Integer pageSize){
//        List<ArticleDetailVO> articleDetailVOS = forumArticleService.selectAllArticleByCategoryIdPage(categoryId, pageNum, pageSize);
//        return JsonResult.ok(articleDetailVOS);
//    }

    @ApiOperation("查询某个作者的全部文章")
    @GetMapping("/select/author/{authorId}")
    public JsonResult<List<ArticleDetailVO>> selectAllArticleByAuthorId(@PathVariable long authorId){
        List<ArticleDetailVO> articleDetailVOS = forumArticleService.selectAllArticleByAuthorId(authorId);
        return JsonResult.ok(articleDetailVOS);
    }

    @ApiOperation("分页查询某个作者的全部文章")
    @GetMapping("/select/author/{authorId}/page")
    public JsonResult<List<ArticleDetailVO>> selectAllArticleByAuthorIdPage(@PathVariable long authorId,Integer pageNum,Integer pageSize){
        List<ArticleDetailVO> articleDetailVOS = forumArticleService.selectAllArticleByAuthorIdPage(authorId, pageNum, pageSize);
        return JsonResult.ok(articleDetailVOS);
    }

    @ApiOperation("查询当前用户点赞的全部文章")
    @GetMapping("/select/like/currentUser")
    public JsonResult<List<ArticleDetailVO>> selectAllArticleByUserLike(){
        List<ArticleDetailVO> articleDetailVOS = forumArticleService.selectAllArticleByUserLike();
        return JsonResult.ok(articleDetailVOS);
    }

    @ApiOperation("分页查询当前用户点赞的全部文章")
    @GetMapping("/select/like/currentUser/page")
    public JsonResult<List<ArticleDetailVO>> selectAllArticleByUserLikePage(Integer pageNum,Integer pageSize){
        List<ArticleDetailVO> articleDetailVOS = forumArticleService.selectAllArticleByUserLikePage(pageNum, pageSize);
        return JsonResult.ok(articleDetailVOS);
    }

    @ApiOperation("查询当前用户收藏过的所有文章")
    @GetMapping("/select/enshrine/currentUser")
    public JsonResult<List<ArticleDetailVO>> selectAllArticleByUserEnshrine(){
        List<ArticleDetailVO> articleDetailVOS = forumArticleService.selectAllArticleByUserEnshrine();
        return JsonResult.ok(articleDetailVOS);
    }

    @ApiOperation("分页查询当前用户收藏过的所有文章")
    @GetMapping("/select/enshrine/currentUser/page")
    public JsonResult<List<ArticleDetailVO>> selectAllArticleByUserEnshrinePage(Integer pageNum,Integer pageSize){
        List<ArticleDetailVO> articleDetailVOS = forumArticleService.selectAllArticleByUserEnshrinePage(pageNum, pageSize);
        return JsonResult.ok(articleDetailVOS);
    }

    @ApiOperation("查询当前用户正在审核的所有文章")
    @GetMapping("/select/check/currentUser")
    public JsonResult<List<ArticleDetailVO>> selectAllArticleInCheck(){
        List<ArticleDetailVO> articleDetailVOS = forumArticleService.selectAllArticleInCheck();
        return JsonResult.ok(articleDetailVOS);
    }

    @ApiOperation("对发表的文章进行审核通过")
    @PostMapping("/check/pass")
    public JsonResult<Void> adminCheckArticlePass(long id){
        forumArticleService.adminCheckArticlePass(id);
        return JsonResult.ok();
    }

    @ApiOperation("对发表的文章进行审核不通过")
    @PostMapping("/check/fail")
    public JsonResult<Void> adminCheckArticleFail(long id){
        forumArticleService.adminCheckArticleFail(id);
        return JsonResult.ok();
    }


    @ApiOperation("查询具体的一篇文章")
    @GetMapping("/select/one/{id}")
    public JsonResult<ArticleDetailVO> selectOneArticleById(@PathVariable long id){
        ArticleDetailVO articleDetailVO = forumArticleService.selectArticleById(id);
        return JsonResult.ok(articleDetailVO);
    }

//    @ApiOperation("用户举报文章")
//    @PostMapping("/report/article/{id}")
//    public JsonResult<Void> updateArticleIsReport(@PathVariable long id ,Integer state){
//        forumArticleService.updateArticleIsReport(id, state);
//        return JsonResult.ok();
//    }

//    @ApiOperation("管理员审核文章")
//    @PostMapping("/check/article/{id}")
//    public JsonResult<Void> adminUpdateArticleIsReport(@PathVariable long id, Integer state){
//        forumArticleService.adminUpdateArticleIsReport(id, state);
//        return JsonResult.ok();
//    }

    @ApiOperation("用户点赞文章")
    @GetMapping("/like/article/{articleId}")
    public JsonResult<Void> likeArticle(@PathVariable long articleId){
        forumArticleService.likeArticle(articleId);
        return JsonResult.ok();
    }

    @ApiOperation("用户收藏文章")
    @GetMapping("/enshrine/article/{articleId}")
    public JsonResult<Void> enshrineArticle(@PathVariable long articleId){
        forumArticleService.enshrineArticle(articleId);
        return JsonResult.ok();
    }

//    @ApiOperation("查询当前用户的所有点赞文章数量")
//    @GetMapping("/select/count/like")
//    public JsonResult<Integer> selectCurrentLikeCount(){
//        int count = forumArticleService.selectCurrentLikeCount();
//        return JsonResult.ok(count);
//    }

//    @ApiOperation("查询当前用户的所有收藏文章数量")
//    @GetMapping("/select/count/enshrine")
//    public JsonResult<Integer> selectCurrentEnshrineCount(){
//        int count = forumArticleService.selectCurrentEnshrineCount();
//        return JsonResult.ok(count);
//    }

    @ApiOperation("批量删除文章")
    @PostMapping("/delete/ids")
    public JsonResult<Void> deleteArticlesByIds(Long... ids){
        forumArticleService.deleteArticleByIds(ids);
        return JsonResult.ok();
    }
}

